﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Specialized;
using System.IO;

namespace OAuth2.Framework.Utility
{
    public static class UriHelper
    {
        /// <summary>
        /// 将NameValueCollection重组成a=a&b=b&c=c格式
        /// </summary>
        /// <param name="queryComponents"></param>
        /// <returns></returns>
        public static string ReconstructQueryString(NameValueCollection queryComponents)
        {
            StringBuilder output = new StringBuilder();
            TextWriter writer = new StringWriter(output);
            string queryComponentFormat = "{0}={1}&";

            foreach (string queryComponentkey in queryComponents) {
                writer.Write(queryComponentFormat,queryComponentkey,queryComponents[queryComponentkey]);
            }
            return output.ToString().TrimEnd('&');
        }
    }
}
